// 添加更多教材数据脚本
const { promiseQuery: query } = require('./db');

async function addMoreTextbooks() {
  try {
    console.log('开始添加更多教材数据...');
    
    // 准备多样化的教材数据
    const newTextbooks = [
      // 新增文学类书籍
      { title: '红楼梦（上下册）', author: '曹雪芹', publisher: '人民文学出版社', isbn: '9787020002207', category_id: 6, seller_id: 2, description: '中国古典文学四大名著之一，保存完好', price: 35.00, original_price: 88.00, condition: 'good', images: '[]', status: 'on_sale' },
      { title: '百年孤独', author: '加西亚·马尔克斯', publisher: '南海出版公司', isbn: '9787544270878', category_id: 6, seller_id: 2, description: '魔幻现实主义经典之作，九成新', price: 28.00, original_price: 55.00, condition: 'like_new', images: '[]', status: 'on_sale' },
      
      // 新增英语类书籍
      { title: '新概念英语4', author: '亚历山大', publisher: '外语教学与研究出版社', isbn: '9787560013480', category_id: 2, seller_id: 2, description: '经典英语学习教材，有少量笔记', price: 22.00, original_price: 39.90, condition: 'good', images: '[]', status: 'on_sale' },
      { title: '英语四级词汇乱序版', author: '新东方', publisher: '浙江教育出版社', isbn: '9787553623871', category_id: 2, seller_id: 2, description: '英语四级备考词汇书，八成新', price: 15.00, original_price: 32.00, condition: 'fair', images: '[]', status: 'on_sale' },
      
      // 新增计算机类书籍
      { title: 'JavaScript高级程序设计', author: '马特·弗里斯比', publisher: '人民邮电出版社', isbn: '9787115586912', category_id: 3, seller_id: 2, description: '前端开发必备书籍，全新', price: 70.00, original_price: 128.00, condition: 'new', images: '[]', status: 'on_sale' },
      { title: 'Python编程：从入门到实践', author: '埃里克·马瑟斯', publisher: '人民邮电出版社', isbn: '9787115428028', category_id: 3, seller_id: 2, description: 'Python入门经典教材，有少量笔记', price: 35.00, original_price: 69.00, condition: 'good', images: '[]', status: 'on_sale' },
      
      // 新增历史类书籍
      { title: '中国近代史', author: '徐中约', publisher: '世界图书出版公司', isbn: '9787506288498', category_id: 7, seller_id: 2, description: '近代史经典著作，九成新', price: 45.00, original_price: 89.00, condition: 'like_new', images: '[]', status: 'on_sale' },
      { title: '全球通史', author: '斯塔夫里阿诺斯', publisher: '北京大学出版社', isbn: '9787301279088', category_id: 7, seller_id: 2, description: '世界史经典教材，保存完好', price: 65.00, original_price: 128.00, condition: 'good', images: '[]', status: 'on_sale' },
      
      // 新增经济类书籍
      { title: '经济学原理', author: '曼昆', publisher: '北京大学出版社', isbn: '9787301259736', category_id: 8, seller_id: 2, description: '经济学入门教材，有少量下划线', price: 40.00, original_price: 79.00, condition: 'good', images: '[]', status: 'on_sale' },
      { title: '货币金融学', author: '米什金', publisher: '中国人民大学出版社', isbn: '9787300248789', category_id: 8, seller_id: 2, description: '金融学经典教材，全新未使用', price: 60.00, original_price: 99.00, condition: 'new', images: '[]', status: 'on_sale' },
      
      // 新增其他类书籍
      { title: '心理学与生活', author: '理查德·格里格', publisher: '人民邮电出版社', isbn: '9787115464385', category_id: 9, seller_id: 2, description: '心理学入门经典，保存完好', price: 55.00, original_price: 99.00, condition: 'good', images: '[]', status: 'on_sale' },
      { title: '普通生物学', author: '陈阅增', publisher: '高等教育出版社', isbn: '9787040396317', category_id: 9, seller_id: 2, description: '生物学基础教材，有笔记', price: 30.00, original_price: 75.00, condition: 'fair', images: '[]', status: 'on_sale' }
    ];
    
    // 插入数据
    let insertedCount = 0;
    for (const book of newTextbooks) {
      const sql = `
        INSERT INTO textbooks 
        (title, author, publisher, isbn, category_id, seller_id, description, price, original_price, \`condition\`, images, status) 
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
      `;
      
      const values = [
        book.title, book.author, book.publisher, book.isbn, 
        book.category_id, book.seller_id, book.description, 
        book.price, book.original_price, book.condition, 
        book.images, book.status
      ];
      
      await query(sql, values);
      insertedCount++;
      console.log(`已添加: ${book.title}`);
    }
    
    // 查询更新后的总数
    const countResult = await query('SELECT COUNT(*) as total FROM textbooks WHERE status = "on_sale"');
    
    console.log('\n✅ 数据添加完成！');
    console.log(`- 成功添加了 ${insertedCount} 本教材`);
    console.log(`- 现在在售教材总数：${countResult[0].total} 本`);
    console.log(`- 教材类型覆盖：数学、英语、计算机、历史、经济、文学、心理学等`);
    
  } catch (error) {
    console.error('\n❌ 添加数据失败：', error.message);
    console.error('错误详情：', error);
  }
}

// 运行脚本
addMoreTextbooks();